import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
    selector: 'app-druid',
    templateUrl: './index.component.html',
    styleUrls: ['./index.component.scss']
})
export class DruidComponent implements OnInit {

    @ViewChild('iframe') iframe: ElementRef;
    url:SafeResourceUrl ="";
    constructor(private sanitizer: DomSanitizer) {}

    ngOnInit() {
        // 使用 DomSanitizer 标记 URL 为安全的
        this.url = this.sanitizer.bypassSecurityTrustResourceUrl(environment.baseUrl + '/druid/login.html');
    }

    setBaseTag(){
        const iframe = document.getElementById('iframe') as HTMLIFrameElement;
        const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
        // 创建 base 标签
        const baseTag = iframeDocument.createElement('base');
        baseTag.href = environment.baseUrl;
        // 将 base 标签插入到 head 中
        iframeDocument.head.appendChild(baseTag);
    }
}
